{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "if not any(path.endswith('textbook') for path in sys.path):\n",
    "    sys.path.append(os.path.abspath('../../..'))\n",
    "from textbook_utils import *"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(ch:pa)=\n",
    "# Case Study: How Accurate Are Air Quality Measurements?"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "California is prone to wildfires, so much so that its\n",
    "residents (like the authors of this book) sometimes say\n",
    "that California is \"always on fire.\"\n",
    "In 2020, 40 separate fires covered the state in smoke,\n",
    "forced thousands of people to evacuate, and caused more than $12 billion in damages ({numref}`fig:ca-fires`).\n",
    "\n",
    "```{figure} figures/ca-fires.jpeg\n",
    "---\n",
    "name: fig:ca-fires\n",
    "alt: ca-fires\n",
    "width: 500px\n",
    "---\n",
    "Satellite image from August 2020 showing smoke covering California (image from [Wikipedia](https://en.wikipedia.org/wiki/File:California_on_fire_ESA22177856.jpeg) licensed under CC BY-SA 3.0 IGO)\n",
    "```"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In places like California, people use air quality measurements to learn what kinds of protective measures they need to take.\n",
    "Depending on conditions, people may wish to wear a mask, use air filters, or avoid going outside altogether."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the US, one important source of air quality information is the [Air Quality System](https://www.epa.gov/aqs) (AQS), run by the US government.\n",
    "AQS places high-quality sensors at locations across the US and makes their data available to the public.\n",
    "These sensors are carefully calibrated to strict standards---in fact, the AQS sensors are generally seen as the gold standard for accuracy.\n",
    "However, they have a few downsides.\n",
    "The sensors are expensive: typically between \\$15,000  and  \\$40,000 each.\n",
    "This means that there are fewer sensors, and they are farther apart.\n",
    "Someone living far away from a sensor might not be able to access AQS data for their personal use.\n",
    "Also, AQS sensors do not provide real-time data. Since the data undergo extensive calibration, they are only released hourly and have a time lag of one to two hours. In essence, the AQS sensors are accurate but not timely."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In contrast, [PurpleAir](https://www2.purpleair.com/) sensors, which we introduced in {numref}`Chapter %s <ch:theory_datadesign>`, sell for about \\$250 and can be easily installed at home.\n",
    "With the lower price point, thousands of people across the US have purchased these sensors for personal use. The sensors can connect to a home WiFi network so that air quality can be easily monitored, and they can report data back to PurpleAir.\n",
    "In 2020, thousands of owners of PurpleAir sensors made their sensors' measurements publicly available.\n",
    "Compared to the AQS sensors, PurpleAir sensors are timelier. They report measurements every two minutes rather than every hour.\n",
    "Since there are more deployed PurpleAir sensors, more people live close enough to a sensor to make use of the data.\n",
    "However, PurpleAir sensors are less accurate.\n",
    "To make the sensors affordable, PurpleAir uses a simpler method to count particles in the air.\n",
    "This means that PurpleAir measurements can report that air quality is worse than it really is (see [Josh Hug's blog post](https://thebolditalic.com/understanding-purpleair-vs-airnow-gov-measurements-of-wood-smoke-pollution-562923a55226)). In essence, PurpleAir sensors tend to be timely but less accurate."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this chapter, we plan to use the AQS sensor measurements to improve the PurpleAir measurements. It's a big task, and we follow the analysis first developed by [Karoline Barkjohn, Brett Gantt, and Andrea Clements](https://amt.copernicus.org/articles/14/4617/2021/) from the US Environmental Protection Agency.\n",
    "Barkjohn and group's work was so successful that, as of this writing, the official US government maps, like the AirNow [Fire and Smoke](https://fire.airnow.gov/) map, include both AQS and PurpleAir sensors and apply Barkjohn's correction to the PurpleAir data."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Our work follows the data science lifecycle, beginning with considering the question and the scope of the available data. Much of our effort is spent cleaning and wrangling the data into shape for analysis, but we also carry out an exploratory data analysis and build a model for generalization. We begin by considering the question and the design and scope of the data. "
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
